<script src='<?php echo DIR_JS?>ui.datepicker.js' type='text/javascript' language='javascript'> </script>
<div class="section" id="sitemaplist">

	<div class="section-title">Bất động sản</div>
    
    <div class="section-content padding1">
    
    	<form name="frm" id="frm" action="<?php echo $action?>" method="post" enctype="multipart/form-data">
        
        	<div class="button right">
            	<input type="button" value="Lưu" class="button" onClick="save()"/>
     	        <input type="button" value="Bỏ qua" class="button" onclick="linkto('?route=addon/bds&sitemapid=<?php echo $_GET['sitemapid']?>')"/>   
     	        <input type="hidden" name="id" value="<?php echo $item['id']?>">
                <input type="hidden" id="bdsid" name="bdsid" value="<?php echo $item['bdsid']?>"/>
            </div>
            <div class="clearer">^&nbsp;</div>
        	<div id="error" class="error" style="display:none"></div>
            <div id="container">
        	
                <ul>
                    <li><a href="#fragment-thongtin"><span>Thông tin bất động sản</span></a></li>
                    <li><a href="#fragment-lienhe"><span>Thông tin liên lạc</span></a></li>
                </ul>
                <div id="fragment-thongtin">
                                      
                    <p>
                        <label>Tiêu đề</label><br />
                        <input type="text" id="tieude" name="tieude" value="<?php echo $item['tieude']?>" class="text" size=60 />
                    </p>
                    <p>
                        <label>Nhu cầu</label><br />
                        <select id="nhucau" name="nhucau">
                            <option value=""></option>
                            <?php foreach($nhucau as $val){ ?>
                            <option value="<?php echo $val['manhom']?>"><?php echo $this->string->getPrefix("&nbsp;&nbsp;&nbsp;&nbsp;",$val['level']-1)?><?php echo $val['tennhom']?></option>
                            <?php } ?>
                        </select>
                    </p>
                    <p>
                        <label>Loại bất động sản</label><br />
                        
                        <select id="loaibds" name="loaibds">
                            <option value=""></option>
                            <?php foreach($loaibds as $val){ ?>
                            <option value="<?php echo $val['manhom']?>"><?php echo $this->string->getPrefix("&nbsp;&nbsp;&nbsp;&nbsp;",$val['level']-1)?><?php echo $val['tennhom']?></option>
                            <?php } ?>
                        </select>
                    </p>
                   	
                    <p>
                        <label>Giá</label><br />
                        <input type="text" id="gia" name="gia" value="<?php echo $this->string->numberFormate($item['gia'])?>" class="text number" size=60 />
                    </p>
                    
                    <p>
                        <label>Hướng</label><br />
                        <select id="huong" name="huong">
                            <option value=""></option>
                            <?php foreach($huong as $val){ ?>
                            <option value="<?php echo $val['manhom']?>"><?php echo $this->string->getPrefix("&nbsp;&nbsp;&nbsp;&nbsp;",$val['level']-1)?><?php echo $val['tennhom']?></option>
                            <?php } ?>
                        </select>
                    </p>
                    
                    <p>
                        <label>Khu vực</label><br />
                        <select id="khuvuc" name="khuvuc">
                            <option value=""></option>
                            <?php foreach($khuvuc as $val){ ?>
                            <option value="<?php echo $val['manhom']?>"><?php echo $this->string->getPrefix("&nbsp;&nbsp;&nbsp;&nbsp;",$val['level']-1)?><?php echo $val['tennhom']?></option>
                            <?php } ?>
                        </select>
                    </p>
                    <p>
                    	<label>Địa chỉ</label><br />
                        <input type="text" id="diachi" name="diachi" value="<?php echo $item['diachi']?>" class="text" size=60 />
                        
                    </p>
                    <p>
                        <label>Diện tích</label><br />
                        <input type="text" id="dientich" name="dientich" value="<?php echo $this->string->numberFormate($item['dientich'])?>" class="text number" size=60 /> m&sup2;
                    </p>
                   	<p>
                        <label>Mô tả</label><br />
                        <textarea name="mota" id="mota" cols="80" rows="10"><?php echo $item['mota']?></textarea>
                    </p>
                    <?php
                    if($this->user->getUserTypeId()=="admin")
                    {
                    ?>
                    <p>
                    	<label>Người nhận liên hệ</label><br />
    					
                        <select id="assignto" name="assignto">
                            <option value=""></option>
                            <?php foreach($users as $val){ ?>
                            <option value="<?php echo $val['userid']?>"><?php echo $val['fullname']?></option>
                            <?php } ?>
                        </select>
                    </p>
                    <?php 
                    }
                    else
                    {
                    ?>
                    	<input type="hidden" id="assignto" name="assignto" value="<?php echo $item['assignto']?>"/>
                    <?php
                    }
                    ?>
                    <p id="pnImage">
                        <label for="image">Image</label><br />
                        <a id="btnAddImage" class="button">Select image</a><br />
                        <img id="preview" src="<?php echo $item['imagethumbnail']?>" />
                        <input type="hidden" id="imagepath" name="imagepath" value="<?php echo $item['imagepath']?>" />
                        <input type="hidden" id="imageid" name="imageid" value="<?php echo $item['imageid']?>" />
                        <input type="hidden" id="imagethumbnail" name="imagethumbnail" value="<?php echo $item['imagethumbnail']?>" />
                    </p>
                    
                    
                    <div id="errorupload" class="error" style="display:none"></div>
                    
                    <div class="loadingimage" style="display:none"></div>
                    <p>
                        <a id="btnAddAttachment" class="button">Attachment</a><br />
                    </p>
                    <p id="attachment">
                    </p>
                    
                    <span id="delfile"></span>
<script language="javascript">
	$(document).ready(function() {
   	// put all your jQuery goodness in here.
<?php
		foreach($attachment as $val)
		{
			if(count($val))
			{
?>
			$('#attachment').append(creatAttachmentRow("<?php echo $val['fileid']?>","<?php echo $val['filename']?>","<?php echo $val['imagethumbnail']?>"));
<?php
			}
		}
?>
 	});

</script>
                    <div class="clearer">&nbsp;</div>

                </div>
                <div id="fragment-lienhe">
                	<p>
                        <label>Tên chủ sở hữu</label><br />
                        <input type="text" id="hotenchusohuu" name="hotenchusohuu" value="<?php echo $item['hotenchusohuu']?>" class="text" size=60 />
                    </p>
                    <p>
                        <label>Điện thoại</label><br />
                        <input type="text" id="dienthoai" name="dienthoai" value="<?php echo $item['dienthoai']?>" class="text" size=60 />
                    </p>
                    <p>
                        <label>Email</label><br />
                        <input type="text" id="email" name="email" value="<?php echo $item['email']?>" class="text" size=60 />
                    </p>
                    
                </div>
                
            </div>
                
            
        </form>
    
    </div>
    
</div>
<script src="<?php echo DIR_JS?>jquery.tabs.pack.js" type="text/javascript"></script>
<script language="javascript">
$(document).ready(function() { 
	setCKEditorType('mota',2);
	$('#container').tabs({ fxSlide: true, fxFade: true, fxSpeed: 'slow' });
	
});
function save()
{
	$.blockUI({ message: "<h1>Please wait...</h1>" }); 
	var oEditor = CKEDITOR.instances['mota'] ;
	var pageValue = oEditor.getData();
	$('textarea#mota').val(pageValue);
	$.post("?route=addon/bds/save", $("#frm").serialize(),
		function(data){
			if(data == "true")
			{
				window.location = "?route=addon/bds&sitemapid=<?php echo $_GET['sitemapid']?>";
			}
			else
			{
			
				$('#error').html(data).show('slow');
				$.unblockUI();
				
			}
			
		}
	);
}

$("#nhucau").val("<?php echo $item['nhucau']?>");
$("#loaibds").val("<?php echo $item['loaibds']?>");
$("#huong").val("<?php echo $item['huong']?>");
$("#khuvuc").val("<?php echo $item['khuvuc']?>");
$("#assignto").val("<?php echo $item['assignto']?>");


var DIR_UPLOADPHOTO = "<?php echo $DIR_UPLOADPHOTO?>";
var DIR_UPLOADATTACHMENT = "<?php echo $DIR_UPLOADATTACHMENT?>";

</script>
<script src='<?php echo DIR_JS?>ajaxupload.js' type='text/javascript' language='javascript'> </script>
<script src="<?php echo DIR_JS?>uploadpreview.js" type="text/javascript"></script>
<script src="<?php echo DIR_JS?>uploadattament.js" type="text/javascript"></script>
